#!/bin/bash
#定义项目部署目录
projectName=permission
apiPath=/home/permission/api/
vuePath=/home/permission/vue/
serverIp=192.168.137.128
#拷贝kill.sh文件到api目录
scp kill.sh root@$serverIp:$apiPath
#服务端创建目录
ssh root@$serverIp   << remotessh
mkdir -p  $apiPath;
mkdir -p  $vuePath;
echo '初始化部署目录成功'
exit
remotessh

#打包vue项目
cd ./bw-permission-vue/
echo '切换到vue目录'
npm run build
#上传静态文件到Linux虚拟主机目录
scp -r dist/* root@$serverIp:$vuePath
echo 'vue静态文件拷贝成功'
cd ..



#打包部署api项目
cd ./bw-permission-api/
mvn clean package
echo 'api项目打包完成'
scp target/bw-permission-api-1.0-SNAPSHOT.jar root@$serverIp:$apiPath
echo '拷贝到Linux部署目录，准备重启'


#kill掉api项目，再启动
ssh root@$serverIp   << remotessh

cd $apiPath;
sh kill.sh $projectName

echo 'API项目进程杀死，准备重启API项目'
sleep 3;
java -jar -Xms12m -Xmx12m -Xss256k ./bw-permission-api-1.0-SNAPSHOT.jar --spring.datasource.password=123456 --file.path=/home/permission/vue/;
echo "已启动项目"

#exit
remotessh
